/**
 * Copyright (c) 2010-2011 julewa.com.  
 * All rights reserved. 
 * 
 * @author Huang Benhua
 * @date 2011-2-20
 * 
**/
package com.julewa;

public class Pair<TA, TB>{
	public TA A=null;
    public TB B=null;
    public Pair(){}
    public Pair(TA a, TB b){
        A=a;B=b;
    }
    public boolean contains(Object o){
        if(o==null)return A==null||B==null;
        return o.equals(A)||o.equals(B);
    }
    
    public TA getA(){
    	return A;
    }
    public TB getB(){
    	return B;
    }
    
    public int hashCode(){
        int c = 0;
        if(A!=null)c+=A.hashCode();
        if(B!=null)c+=B.hashCode();
        return c;
    }
    @SuppressWarnings("unchecked")
	public boolean equals(Object o){
        if(o==null)return false;
        if(this == o)return true;
        Pair<TA, TB> p = (Pair<TA, TB>)o;
        if(A==p.A&&B==p.B)return true;
        if(A==null&&p.A!=null)return false;
        if(B==null&&p.B!=null)return false;
        return A.equals(p.A)&&B.equals(p.B);
    }
    
    public String toString(){
        return A + "@" + B;
    }
	    
}
